package cn.wolfcode.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;


import java.util.Date;
import java.util.Map;

public class JWTUtils {

    private static String SingKey = "WolfCode";
    private static long EXPIRE = 1000 * 60 * 60 * 24 * 7;

    public static String createToken(Map<String,Object> claims){
       return Jwts.builder()
                .setClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis() + EXPIRE))
                .signWith(SignatureAlgorithm.HS512, SingKey)
                .compact();

    }
       public static Claims parseToken(String jwt){
           return Jwts.parser()
                   .setSigningKey(SingKey)
                   .parseClaimsJws(jwt)
                   .getBody();
       }
}
